package gt.bank.tool

import  groovy.swing.* 
import  javax.swing.* 
import  java.awt.* 
import javax.swing.*

/**
 * @author Goodtiger
 *
 */
public class EBookReader{

	def swing = new SwingBuilder()
	JFrame frame 
	def toolkit  =  Toolkit.getDefaultToolkit()
	def screenSize = toolkit.getScreenSize()

	def WIDTH  =   320 
	def HEIGHT  =   200 
	int  X  =  (screenSize.width  -  WIDTH)  /   2 
	int  Y  =  (screenSize.height  -  HEIGHT)  /   2 

	File file

	String path

	private void run(){
		UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel")
		frame  =  swing.frame(title:' EBookReader ',
				size: [WIDTH, HEIGHT],location: [X, Y],
				layout:new  BorderLayout(),
				defaultCloseOperation:WindowConstants.DISPOSE_ON_CLOSE){
			menuBar(constraints: BorderLayout.NORTH){
				menu(text:"File"){
					menuItem(){
						action(close())
					}
				}
				menu(text:"Help"){
					menuItem(){
						action(about())
					}
				}
			}
			panel(constraints: BorderLayout.CENTER) {
				tableLayout {
					tr{
						td{
							button(id:"openBtn"){
								action(open())
							}
						}		
					}
				}
			}
			textField(id:  "info" , constraints: BorderLayout.SOUTH)
		}
		 frame.setResizable( false )
		 frame.setVisible( true )
	}

	def open(){
		 return  swing.action(name:"Open", closure:{
			 def chooser = new JFileChooser()
			 int returnVal = chooser.showOpenDialog(frame)
			 if(returnVal == JFileChooser.APPROVE_OPTION) {
				 file = chooser.getSelectedFile()
				 swing.info.text = "Opened"+file.getName()
				 swing.processBtn.setEnabled(true)
			 }

		 })
	}
	def about(){
		return  swing.action(name:"About", closure:{
			
		 })
	}
	def close(){
		return  swing.action(name:"Exit", closure:{
			 System.exit(0)
		 })
	}
	/**
	 * @param args
	 */
	public static void main(def args){
		  new  EBookReader().run()
	}

}
